package com.wontube.smr.web.controller.admin;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.wontube.client.extension.remote.session.ISessionHandler;
import com.wontube.client.modle.vo.ClientSession;
import com.wontube.client.remote.Remoting;

/**
 * @author tanggf(2012-6-4)
 *
 */
@Controller
@RequestMapping("/admin/clientsession")
public class AdminClientSessionController {
	@RequestMapping("")
	public ModelAndView client_session_index(){
		ModelAndView mv = new ModelAndView("admin/clientsession/session_index");	
		ISessionHandler handler = getSessionHandler();
		int totalCount = handler.getSessionCount();
		mv.addObject("totalCount", totalCount);
		
		return mv;
	}
	
	@RequestMapping("/list")
	public ModelAndView list_client_session(@RequestParam("agent") String agent){
		ModelAndView mv = new ModelAndView("admin/clientsession/session_list");
		ISessionHandler handler = getSessionHandler();
		List<ClientSession> clientSessions = handler.listSessions(agent);
		mv.addObject("clientSessions", clientSessions);		
		int totalCount = handler.getSessionCount();
		mv.addObject("totalCount", totalCount);
		
		return mv;
	}
	
	private ISessionHandler getSessionHandler(){
		Remoting<ISessionHandler> remoting = new Remoting<ISessionHandler>();
		return remoting.createService(ISessionHandler.class);
	}
}
